#!/bin/zsh

BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "开始构建..."
echo "---注意当前分支为 $BRANCH---"

echo ">>> 执行maven编译，生成最新jar包"
mvn clean package -Dmaven.test.skip=true || { echo "Maven 编译失败"; exit 1; }

DATE_FORMAT=$(date +%Y%m%d.%H%M.%S)
TAG="$(git rev-parse --short HEAD).$DATE_FORMAT"
# 构建镜像并获取镜像 ID
echo ">>> 执行镜像构建 ai-treasure-chest:$TAG"
IMAGE_ID=$(docker build --platform linux/amd64 -q -t ai-treasure-chest:"$TAG" .)

# 打标签
echo ">>> 执行镜像打标，tag=$TAG"
docker tag "$IMAGE_ID" registry.cn-hangzhou.aliyuncs.com/hongmin_image_registory/ai-treasure-chest:"$TAG"

# 推送到私有仓库
echo ">>> 推送镜像至私有仓库"
docker push registry.cn-hangzhou.aliyuncs.com/hongmin_image_registory/ai-treasure-chest:"$TAG"

echo ">>> SUCCESS 镜像推送完成，tag=$TAG"

# 121.11.118.20
# registry.cn-hangzhou.aliyuncs.com/hongmin_image_registory/ai-treasure-chest:[镜像版本号]
# registry.cn-hangzhou.aliyuncs.com/hongmin_image_registory/ai-treasure-chest-web:[镜像版本号]
# registry.cn-hangzhou.aliyuncs.com/hongmin_image_registory/ai-treasure-chest-corp-admin:[镜像版本号]
# registry.cn-hangzhou.aliyuncs.com/hongmin_image_registory/ai-treasure-chest-admin:[镜像版本号]
